﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using CPPEI.Coolzon.ServiceProxy.DataServiceRef;
using System.Windows.Media;
using System.Windows.Media.Effects;
using System.Windows;
using System.ComponentModel;

namespace CPPEI.Coolzon.UI.DataPartLib
{
    public partial class DataAnimationLabelBase : DataItemPart
    {
        private double? _XCharWeight;
        /// <summary>
        /// 单个字符的宽度
        /// </summary>
        [Category("其他")]
        [DisplayName("单个字符的宽度")]
        [Description("XCharWeight")]
        [Editor(typeof(UI.XProperty.Editors.XDoubleEditor), typeof(UI.XProperty.XPropertyValueEditor))]
        [XProperty(XPropertyCategory.Other, "XCharWeight", "单个字符的宽度")]
        public double? XCharWeight
        {
            get { return _XCharWeight; }
            set
            {
                _XCharWeight = value;
                Refresh();
            }
        }
        private string _XFlowDirection;
        /// <summary>
        /// 
        /// </summary>
        [Category("其他")]
        [DisplayName("向左靠拢LeftToRight或向右靠拢 RightToLeft")]
        [Description("XFlowDirection")]
        [Editor(typeof(UI.XProperty.Editors.XStringEditor), typeof(UI.XProperty.XPropertyValueEditor))]
        [XProperty(XPropertyCategory.Other, "XFlowDirection", "向左靠拢LeftToRight或向右靠拢 RightToLeft")]
        public string XFlowDirection
        {
            get { return _XFlowDirection; }
            set
            {
                _XFlowDirection = value;
                Refresh();
            }
        }
        private bool? _XIsShowShadow;
        /// <summary>
        /// 是否显示阴影
        /// </summary>
        [Category("其他")]
        [DisplayName("是否显示阴影")]
        [Description("XIsShowShadow")]
        [Editor(typeof(UI.XProperty.Editors.XBooleanEditor), typeof(UI.XProperty.XPropertyValueEditor))]
        [XProperty(XPropertyCategory.Other, "XIsShowShadow", "是否显示阴影")]
        public bool? XIsShowShadow
        {
            get { return _XIsShowShadow; }
            set
            {
                _XIsShowShadow = value;
                Refresh();
            }
        }
        private string _XShadowColor;
        /// <summary>
        /// 阴影颜色
        /// </summary>
        [Category("其他")]
        [DisplayName("阴影颜色#FF000000")]
        [Description("XShadowColor")]
        [Editor(typeof(UI.XProperty.Editors.XStringEditor), typeof(UI.XProperty.XPropertyValueEditor))]
        [XProperty(XPropertyCategory.Other, "XShadowColor", "阴影颜色#FF000000")]
        public string XShadowColor
        {
            get { return _XShadowColor; }
            set
            {
                _XShadowColor = value;
                Refresh();
            }
        }
        private Double? _XShadowDirection;
        /// <summary>
        /// 阴影方向
        /// </summary>
        [Category("其他")]
        [DisplayName("阴影方向0-360")]
        [Description("XShadowDirection")]
        [Editor(typeof(UI.XProperty.Editors.XDoubleEditor), typeof(UI.XProperty.XPropertyValueEditor))]
        [XProperty(XPropertyCategory.Other, "XShadowDirection", "阴影方向0-360")]
        public Double? XShadowDirection
        {
            get
            {
                return _XShadowDirection;
            }
            set
            {
                _XShadowDirection = value;
                Refresh();
            }
        }
        private Double? _XShadowDepth;
        /// <summary>
        /// 阴影深度
        /// </summary>
        [Category("其他")]
        [DisplayName("阴影深度")]
        [Description("XShadowDepth")]
        [Editor(typeof(UI.XProperty.Editors.XDoubleEditor), typeof(UI.XProperty.XPropertyValueEditor))]
        [XProperty(XPropertyCategory.Other, "XShadowDepth", "阴影深度")]
        public Double? XShadowDepth
        {
            get
            {
                return _XShadowDepth;
            }
            set
            {
                _XShadowDepth = value;
                Refresh();
            }
        }
        private Double? _XBlurRadius;
        /// <summary>
        /// Blur半径
        /// </summary>
        [Category("其他")]
        [DisplayName("阴影扩散半径")]
        [Description("XBlurRadius")]
        [Editor(typeof(UI.XProperty.Editors.XDoubleEditor), typeof(UI.XProperty.XPropertyValueEditor))]
        [XProperty(XPropertyCategory.Other, "XBlurRadius", "阴影扩散半径")]
        public Double? XBlurRadius
        {
            get { return _XBlurRadius; }
            set
            {
                _XBlurRadius = value;
                Refresh();
            }
        }

        private string _XFormatString;
        /// <summary>
        /// 显示格式
        /// 01 {0:d2}
        /// </summary>
        [Category("其他")]
        [DisplayName("显示格式")]
        [Description("XFormatString")]
        [Editor(typeof(UI.XProperty.Editors.XStringEditor), typeof(UI.XProperty.XPropertyValueEditor))]
        [XProperty(XPropertyCategory.Other, "XFormatString", "显示格式")]
        public string XFormatString
        {
            get { return _XFormatString; }
            set
            {
                _XFormatString = value;
                Refresh();
            }
        }
        private Thickness _XLabelMargin;
        /// <summary>
        /// 文本外边距
        /// </summary>
        [Category("其他")]
        [DisplayName("文本外边距")]
        [Description("XLabelMargin")]
        [Editor(typeof(UI.XProperty.Editors.XThicknessEditor), typeof(UI.XProperty.XPropertyValueEditor))]
        [XProperty(XPropertyCategory.Other, "XLabelMargin", "文本外边距")]
        public Thickness XLabelMargin
        {
            get { return _XLabelMargin; }
            set
            {
                _XLabelMargin = value;
                Refresh();
            }
        }
        private Thickness _XLabelPadding;
        /// <summary>
        /// 文本内边距
        /// </summary>
        [Category("其他")]
        [DisplayName("文本内边距")]
        [Description("XLabelPadding")]
        [Editor(typeof(UI.XProperty.Editors.XThicknessEditor), typeof(UI.XProperty.XPropertyValueEditor))]
        [XProperty(XPropertyCategory.Other, "XLabelPadding", "文本内边距")]
        public Thickness XLabelPadding
        {
            get { return _XLabelPadding; }
            set
            {
                _XLabelPadding = value;
                Refresh();
            }
        }
        private double _XFontSize;
        /// <summary>
        /// 字体大小
        /// </summary>
        [Category("其他")]
        [DisplayName("字体大小")]
        [Description("XFontSize")]
        [Editor(typeof(UI.XProperty.Editors.XDoubleEditor), typeof(UI.XProperty.XPropertyValueEditor))]
        [XProperty(XPropertyCategory.Other, "XFontSize", "字体大小")]
        public double XFontSize
        {
            get
            {
                return _XFontSize;
            }
            set
            {
                _XFontSize = value;
                Refresh();
            }
        }
        private HorizontalAlignment _XTextAlign;
        /// <summary>
        /// 字体问题
        /// </summary>
        [Category("其他")]
        [DisplayName("字体水平位置")]
        [Description("XTextAlign")]
        [Editor(typeof(UI.XProperty.Editors.XHorizontalAlignmentEditor), typeof(UI.XProperty.XPropertyValueEditor))]
        [XProperty(XPropertyCategory.Other, "XTextAlign", "字体水平位置")]
        public HorizontalAlignment XTextAlign
        {
            get
            {
                return _XTextAlign;
            }
            set
            {
                _XTextAlign = value;
                Refresh();
            }
        }
        private VerticalAlignment _XTextVAlign;
        /// <summary>
        /// 字体问题
        /// </summary>
        [Category("其他")]
        [DisplayName("字体垂直位置")]
        [Description("XTextVAlign")]
        [Editor(typeof(UI.XProperty.Editors.XVerticalAlignmentEditor), typeof(UI.XProperty.XPropertyValueEditor))]
        [XProperty(XPropertyCategory.Other, "XTextVAlign", "字体垂直位置")]
        public VerticalAlignment XTextVAlign
        {
            get
            {
                return _XTextVAlign;
            }
            set
            {
                _XTextVAlign = value;
                Refresh();
            }
        }
        private FontFamily _XFont;
        /// <summary>
        /// 字体样式
        /// </summary>
        [Category("其他")]
        [DisplayName("字体")]
        [Description("XFont")]
        [Editor(typeof(UI.XProperty.Editors.XFontFamilyEditor), typeof(UI.XProperty.XPropertyValueEditor))]
        [XProperty(XPropertyCategory.Other, "XFont", "字体")]
        public FontFamily XFont
        {
            get
            {
                return _XFont;
            }
            set
            {
                _XFont = value;
                Refresh();
            }
        }
        private FontWeight _XFontWeight;
        [Category("其他")]
        [DisplayName("字体样式")]
        [Description("XFontWeight")]
        [Editor(typeof(UI.XProperty.Editors.XFontWeightEditor), typeof(UI.XProperty.XPropertyValueEditor))]
        [XProperty(XPropertyCategory.Other, "XFontWeight", "字体样式")]
        public FontWeight XFontWeight
        {
            get
            {
                return _XFontWeight;
            }
            set
            {
                _XFontWeight = value;
                Refresh();
            }
        }
        private ImageSourceFile _XDigitalImage;
        [Category("其他")]
        [DisplayName("计数背景")]
        [Description("XDigitalImage")]
        [Editor(typeof(UI.XProperty.Editors.XImageSourceFileEditor), typeof(UI.XProperty.XPropertyValueEditor))]
        [XProperty(XPropertyCategory.Other, "XDigitalImage", "计数背景")]
        public ImageSourceFile XDigitalImage
        {
            get { return _XDigitalImage; }
            set
            {
                _XDigitalImage = value;
                Refresh();
            }
        }

        protected override void OnDataItemBinding(DataItem dataItem)
        {

        }

        protected DropShadowEffect GetDropShadowEffect()
        {
            if (XIsShowShadow != null && XIsShowShadow.Value)
            {
                DropShadowEffect effect = new DropShadowEffect();
                if (!string.IsNullOrWhiteSpace(XShadowColor))
                {
                    effect.Color = (Color)ColorConverter.ConvertFromString(XShadowColor);
                }
                if (XShadowDirection != null)
                {
                    effect.Direction = XShadowDirection.Value;
                }
                if (XShadowDepth != null)
                {
                    effect.ShadowDepth = XShadowDepth.Value;
                }
                if (XBlurRadius != null)
                {
                    effect.BlurRadius = XBlurRadius.Value;
                }
                return effect;
            }
            else
                return null;
        }

        protected double GetEveryCharWeight(int itemValueStringLength)
        {
            double everyWidth = Width / (double)itemValueStringLength - XLabelMargin.Left - XLabelMargin.Right;
            if (XCharWeight != null)
            {
                everyWidth = XCharWeight.Value;
            }
            return everyWidth;
        }
    }
}
